#include "mid_S32kToAutoChip_Hal.h"

#include "Std_Types.h"
#include "types.h"
#include "Dcm.h"
#include "app_sysboot.h"
#include "app_DiagnosticDem.h"

extern DiagService_info_t g_diag_error;

static uint8_t Dcm_ReadDtcDetectionCondition(void)
{
	uint8_t ret = TRUE;

	if(g_diag_error.time_acc_on < 2000)
	{
		ret = FALSE;
	}
	else if((g_sysboot_service.pow_volt < 60) || (g_sysboot_service.pow_volt > 180))
	{
		ret = FALSE;
	}
	else
	{
	}

	return ret;
}
static uint8_t Dcm_ClearDtcDetectionCondition(void)
{
	uint8_t ret = TRUE;

	if(g_diag_error.time_acc_on < 2000)
	{
		// ret = FALSE;
	}
	else if((g_sysboot_service.pow_volt < 90) || (g_sysboot_service.pow_volt > 160))
	{
		ret = FALSE;
	}
	else
	{

	}

	return ret;
}

Std_ReturnType Dcm_DspDidConditionCheckClearDtcFnc(void)
{
	Std_ReturnType ret = E_OK;
	if(Dcm_ClearDtcDetectionCondition() == FALSE)
	{
		ret = E_NOT_OK;
	}
	return ret;
}

Std_ReturnType Dcm_DspDidConditionCheckReadDtcFnc(Dcm_NegativeResponseCodeType *errorCode)
{
	Std_ReturnType ret = E_OK;
	if(Dcm_ReadDtcDetectionCondition() == FALSE)
	{
		*errorCode = DCM_E_CONDITIONSNOTCORRECT;
		ret = E_NOT_OK;
	}
	else
	{
		*errorCode = DCM_E_POSITIVERESPONSE;
	}
	return ret;
}
